<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blogs/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blogs/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blogs/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blogs/images/apple-touch-icon.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/blogs/images/favicon-32x32.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/blogs/images/favicon-16x16.png?v=5.1.3">


  <link rel="mask-icon" href="/blogs/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="Node.js," />










<meta name="description" content="Express身份认证1.身份认证 什么是身份认证？  身份认证（Authentication）又称“身份验证”、”鉴权“，是指通过一定的手段，完成对用户的身份确认  为什么需要身份认证？  身份认证的目的是为了确认当前所声称为某种身份的用户，确实是所声称的用户。比如去快递是，我们需要证明这份快递是我们的，要么通过取货码，要么通过手机尾号来进行身份验证。  不同种类的身份认证  服务端渲染的开发模">
<meta property="og:type" content="article">
<meta property="og:title" content="Express身份认证">
<meta property="og:url" content="https://louchaoyy.gitee.io/blogs/2022/04/28/Express%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81/index.html">
<meta property="og:site_name" content="Chao&#39;s blog">
<meta property="og:description" content="Express身份认证1.身份认证 什么是身份认证？  身份认证（Authentication）又称“身份验证”、”鉴权“，是指通过一定的手段，完成对用户的身份确认  为什么需要身份认证？  身份认证的目的是为了确认当前所声称为某种身份的用户，确实是所声称的用户。比如去快递是，我们需要证明这份快递是我们的，要么通过取货码，要么通过手机尾号来进行身份验证。  不同种类的身份认证  服务端渲染的开发模">
<meta property="og:locale">
<meta property="og:image" content="https://louchaoyy.gitee.io/blogs/2022/04/28/Express%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81/pic1.png">
<meta property="og:image" content="https://louchaoyy.gitee.io/blogs/2022/04/28/Express%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81/pic2.png">
<meta property="og:image" content="https://louchaoyy.gitee.io/blogs/2022/04/28/Express%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81/pic3.png">
<meta property="og:image" content="https://louchaoyy.gitee.io/blogs/2022/04/28/Express%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81/pic4.png">
<meta property="article:published_time" content="2022-04-28T11:05:33.000Z">
<meta property="article:modified_time" content="2022-04-28T13:44:58.179Z">
<meta property="article:author" content="Chaoyxy">
<meta property="article:tag" content="Node.js">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://louchaoyy.gitee.io/blogs/2022/04/28/Express%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81/pic1.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '',
    scheme: 'Gemini',
    version: '5.1.3',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://louchaoyy.gitee.io/blogs/2022/04/28/Express身份认证/"/>





  <title>Express身份认证 | Chao's blog</title>
  








<meta name="generator" content="Hexo 5.4.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blogs/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Chao's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blogs/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/blogs/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blogs/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://louchaoyy.gitee.io/blogs/blogs/2022/04/28/Express%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blogs/images/cat.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Chao's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Express身份认证</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2022-04-28T19:05:33+08:00">
                2022-04-28
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/blogs/2022/04/28/Express%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2022/04/28/Express身份认证/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="Express身份认证"><a href="#Express身份认证" class="headerlink" title="Express身份认证"></a>Express身份认证</h1><h2 id="1-身份认证"><a href="#1-身份认证" class="headerlink" title="1.身份认证"></a>1.身份认证</h2><ul>
<li>什么是身份认证？</li>
</ul>
<p>身份认证（Authentication）又称“身份验证”、”鉴权“，是指通过一定的手段，完成对用户的身份确认</p>
<ul>
<li>为什么需要身份认证？</li>
</ul>
<p>身份认证的目的是为了确认当前所声称为某种身份的用户，确实是所声称的用户。比如去快递是，我们需要证明这份快递是我们的，要么通过取货码，要么通过手机尾号来进行身份验证。</p>
<ul>
<li>不同种类的身份认证</li>
</ul>
<p>服务端渲染的开发模式推荐使用**<code>session</code>**认证机制</p>
<p>前后端分离的开发模式推荐使用**<code>JWT</code>**认证机制</p>
<h2 id="2-Session认证机制"><a href="#2-Session认证机制" class="headerlink" title="2.Session认证机制"></a>2.Session认证机制</h2><ul>
<li>由于HTTP协议的是无状态的</li>
</ul>
<p>就是说客户端<strong>每次的HTTP请求都是独立的</strong>，连续多个请求之间没有直接的关系。<strong>服务器不会主动保留每次HTTP请求的状态。</strong>示意图如下：</p>
<img src="/blogs/2022/04/28/Express%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81/pic1.png" class title="HTTP无状态的示意图">

<ul>
<li>超市收银员为了记住你是会员，她通过会员卡的形式，以后你购物只需要出示会员卡，就能证明你是会员了。</li>
</ul>
<p>使用会员卡认证身份的方式，在WEB开发中专业术语叫<strong>Cookie</strong></p>
<ul>
<li>什么是cookie？</li>
</ul>
<p>Cookie是存储在用户浏览器中的一段不超过4KB的字符串，它由一个名称Name和一个值Value和其他几个用于控制Cookie的有效期，安全性，使用范围的可选属性组成。</p>
<span id="more"></span>

<p>不同域名下的Cookie各自独立，每当客户端发起请求时，会自动把当前域名下所有未过期的Cookie一同发送到服务器。</p>
<ul>
<li>Cookie的特性</li>
</ul>
<ol>
<li>自动发送</li>
<li>域名独立</li>
<li>过期时限</li>
<li>4KB限制</li>
</ol>
<ul>
<li>cookie在身份认证中的作用</li>
</ul>
<p>客户端在第一次请求服务器时，服务器通过响应头的形式，向客户端发送一个身份认证的Cookie，客户端会自动将Cookie保存在浏览器中，随后，当客户端浏览器请求服务器的时候，浏览器会自动将身份认证相关的Cookie，通过请求头的形式发送给服务器，服务器科技验明客户端的身份。原理如下：</p>
<img src="/blogs/2022/04/28/Express%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81/pic2.png" class title="cookie认证原理">

<ul>
<li>cookie认证的不安全性</li>
</ul>
<p>由于cookie是存储在浏览器中的，而且浏览器也提供了读写cookie的API，因此cookie很容易被伪造，不具有安全性，因此不建议服务器将重要的隐私数据，通过cookie的形式发送给浏览器。</p>
<p>举个例子，超市顾客看到有会员卡的用户，通过出示一张会员卡就可以享受到打折优惠的活动，因此他自己也伪造了一张会员卡，去进行享受打折活动。</p>
<ul>
<li>提高身份认证的安全性</li>
</ul>
<p>为了防止客户伪造会员卡，收银员在拿到客户出示的会员卡之后，需要在收银机上进行刷卡认证，只有收音机确认存在的会员卡，才能正常使用。</p>
<p>因此，<strong>”会员卡“+”刷卡认证“ 的设计理念，就是Session认证机制的精髓</strong></p>
<ul>
<li>session认证的工作原理</li>
</ul>
<p>如下图：</p>
<img src="/blogs/2022/04/28/Express%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81/pic3.png" class title="session认证工作原理">

<h2 id="3-Express中的session认证"><a href="#3-Express中的session认证" class="headerlink" title="3.Express中的session认证"></a>3.Express中的session认证</h2><ul>
<li>安装express-session中间件，安装成功之后需要使用app.use()来进行注册session中间件</li>
</ul>
<p>安装：<code>npm install express-session --save</code></p>
<ul>
<li>示例代码：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 导入session中间件</span></span><br><span class="line"><span class="keyword">const</span> session = <span class="built_in">require</span>(<span class="string">&#x27;express-session&#x27;</span>);</span><br><span class="line"><span class="comment">// 配置session中间件</span></span><br><span class="line">app.use(session(&#123;</span><br><span class="line">    <span class="attr">secret</span>:<span class="string">&#x27;chaoyxylove_&amp;&amp;_^_^&#x27;</span>,<span class="comment">//secret属性可以是任意字符串</span></span><br><span class="line">    <span class="attr">resave</span>:<span class="literal">false</span>,               <span class="comment">//固定写法</span></span><br><span class="line">    <span class="attr">saveUninitialized</span>:<span class="literal">true</span>,     <span class="comment">//固定写法</span></span><br><span class="line">&#125;))</span><br></pre></td></tr></table></figure>

<ul>
<li>向session中存数据</li>
</ul>
<p>当express-session中间件配置成功后，即可通过req.session来访问和使用session对象,从而存储用户的关键信息，示例代码如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 登录</span></span><br><span class="line">router.post(<span class="string">&#x27;/login&#x27;</span>,<span class="function">(<span class="params">req,res</span>)=&gt;</span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(req.body.username!==<span class="string">&#x27;admin&#x27;</span>||req.body.password!==<span class="string">&#x27;chao3210.&#x27;</span>)&#123;</span><br><span class="line">        res.send(&#123;</span><br><span class="line">            <span class="attr">status</span>:<span class="number">0</span>,</span><br><span class="line">            <span class="attr">msg</span>:<span class="string">&quot;登录失败&quot;</span></span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        req.session.user = req.body;    <span class="comment">//将用户信息存储到session中</span></span><br><span class="line">        req.session.islogin = <span class="literal">true</span>;     <span class="comment">//将用户登录状态存储到session中</span></span><br><span class="line">        res.send(&#123;</span><br><span class="line">            <span class="attr">status</span>:<span class="number">200</span>,</span><br><span class="line">            <span class="attr">msg</span>:<span class="string">&quot;登录成功！&quot;</span></span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>当postman发起请求后</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="attr">&quot;status&quot;</span>: <span class="number">200</span>,</span><br><span class="line">    <span class="attr">&quot;msg&quot;</span>: <span class="string">&quot;登录成功！&quot;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>从session中获取数据</li>
</ul>
<p>直接采用req.session来取值</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 获取session</span></span><br><span class="line">router.get(<span class="string">&#x27;/getuser&#x27;</span>,<span class="function">(<span class="params">req,res</span>)=&gt;</span>&#123;</span><br><span class="line">    <span class="comment">// 判断用户是否登录</span></span><br><span class="line">    <span class="keyword">if</span>(!req.session.islogin)&#123;</span><br><span class="line">        <span class="keyword">return</span> res.send(&#123;</span><br><span class="line">            <span class="attr">status</span>:<span class="number">0</span>,</span><br><span class="line">            <span class="attr">msg</span>:<span class="string">&quot;fail&quot;</span></span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        res.send(&#123;</span><br><span class="line">            <span class="attr">status</span>:<span class="number">200</span>,</span><br><span class="line">            <span class="attr">msg</span>:<span class="string">&#x27;success&#x27;</span>,</span><br><span class="line">            <span class="attr">username</span>:req.session.user.username</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>postman发起<code>http://127.0.0.1:8008/api/getuser</code>的请求</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="attr">&quot;status&quot;</span>: <span class="number">200</span>,</span><br><span class="line">    <span class="attr">&quot;msg&quot;</span>: <span class="string">&quot;success&quot;</span>,</span><br><span class="line">    <span class="attr">&quot;username&quot;</span>: <span class="string">&quot;admin&quot;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>清空session</li>
</ul>
<p>调用req.session.destroy()函数，即可清空当前保存的session信息</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 清空session</span></span><br><span class="line">router.get(<span class="string">&#x27;/clearsession&#x27;</span>,<span class="function">(<span class="params">req,res</span>)=&gt;</span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">&quot;清空前的session&quot;</span>,req.session);</span><br><span class="line">    req.session.destroy();</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">&quot;清空session后&quot;</span>,req.session)</span><br><span class="line">    res.send(&#123;</span><br><span class="line">        <span class="attr">status</span>:<span class="number">0</span>,</span><br><span class="line">        <span class="attr">msg</span>:<span class="string">&quot;退出登录成功&quot;</span></span><br><span class="line">    &#125;)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>postman发起<code>http://127.0.0.1:8008/api/clearsession</code>的请求</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//后台控制台</span></span><br><span class="line">清空前的session Session &#123;</span><br><span class="line">  cookie: &#123; path: &#x27;/&#x27;, _expires: <span class="literal">null</span>, originalMaxAge: <span class="literal">null</span>, httpOnly: <span class="literal">true</span> &#125;,</span><br><span class="line">  user: &#123; username: &#x27;admin&#x27;, password: &#x27;chao3210.&#x27; &#125;,</span><br><span class="line">  islogin: <span class="literal">true</span></span><br><span class="line">&#125;</span><br><span class="line">清空session后 undefined</span><br><span class="line"><span class="comment">//前端收到的响应</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="attr">&quot;status&quot;</span>: <span class="number">0</span>,</span><br><span class="line">    <span class="attr">&quot;msg&quot;</span>: <span class="string">&quot;退出登录成功&quot;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="附录："><a href="#附录：" class="headerlink" title="附录："></a>附录：</h1><h2 id="1-express-mysql"><a href="#1-express-mysql" class="headerlink" title="1.express-mysql"></a>1.express-mysql</h2><p>安装mysql,配置mysql在之前的文章中已经说得很清楚，这里不多做赘述。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install mysql --save</span><br></pre></td></tr></table></figure>

<p>简单配置mysql</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 导入模块</span></span><br><span class="line"><span class="keyword">const</span> mysql = <span class="built_in">require</span>(<span class="string">&#x27;mysql&#x27;</span>)</span><br><span class="line"><span class="comment">// 创建连接</span></span><br><span class="line"><span class="keyword">const</span> db = mysql.createPool(&#123;</span><br><span class="line">    <span class="attr">host</span>:<span class="string">&quot;124********80&quot;</span>,</span><br><span class="line">    <span class="attr">user</span>:<span class="string">&quot;root&quot;</span>,</span><br><span class="line">    <span class="attr">port</span>:<span class="number">3307</span>,</span><br><span class="line">    <span class="attr">password</span>:<span class="string">&quot;y*******9@&quot;</span>,</span><br><span class="line">    <span class="attr">database</span>:<span class="string">&quot;mytest&quot;</span></span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 查询数据库</span></span><br><span class="line">router.post(<span class="string">&#x27;/handdatabase&#x27;</span>,<span class="function">(<span class="params">req,res</span>)=&gt;</span>&#123;</span><br><span class="line">    <span class="keyword">const</span> sqlStr = <span class="string">&#x27;SELECT * FROM flutter_list&#x27;</span></span><br><span class="line">    db.query(sqlStr,<span class="function">(<span class="params">err,result</span>)=&gt;</span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (err) &#123;</span><br><span class="line">            <span class="built_in">console</span>.log(err.message)</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            <span class="built_in">console</span>.log(<span class="string">&#x27;success&#x27;</span>)</span><br><span class="line">            res.send(&#123;</span><br><span class="line">                <span class="attr">status</span>:<span class="number">200</span>,</span><br><span class="line">                <span class="attr">data</span>:result</span><br><span class="line">            &#125;)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>postman发起<code>http://127.0.0.1:8008/api/handdatabase</code>的请求的结果如下</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="attr">&quot;status&quot;</span>: <span class="number">200</span>,</span><br><span class="line">    <span class="attr">&quot;data&quot;</span>: [</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="attr">&quot;id&quot;</span>: <span class="number">1</span>,</span><br><span class="line">            <span class="attr">&quot;title&quot;</span>: <span class="string">&quot;Candy shop&quot;</span>,</span><br><span class="line">            <span class="attr">&quot;author&quot;</span>: <span class="string">&quot;Mohamed&quot;</span>,</span><br><span class="line">            <span class="attr">&quot;imageUrl&quot;</span>: <span class="string">&quot;http://chaoyxy.cn/data/User/admin/home/desktop/images/cat.jpg&quot;</span></span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="attr">&quot;id&quot;</span>: <span class="number">2</span>,</span><br><span class="line">            <span class="attr">&quot;title&quot;</span>: <span class="string">&quot;Childhood in a picture&quot;</span>,</span><br><span class="line">            <span class="attr">&quot;author&quot;</span>: <span class="string">&quot;Google&quot;</span>,</span><br><span class="line">            <span class="attr">&quot;imageUrl&quot;</span>: <span class="string">&quot;http://chaoyxy.cn/data/User/admin/home/desktop/images/my.jpg&quot;</span></span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="attr">&quot;id&quot;</span>: <span class="number">3</span>,</span><br><span class="line">            <span class="attr">&quot;title&quot;</span>: <span class="string">&quot;Alibaba Shop&quot;</span>,</span><br><span class="line">            <span class="attr">&quot;author&quot;</span>: <span class="string">&quot;Alibaba&quot;</span>,</span><br><span class="line">            <span class="attr">&quot;imageUrl&quot;</span>: <span class="string">&quot;http://chaoyxy.cn/data/User/admin/home/desktop/images/background.jpg&quot;</span></span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="attr">&quot;id&quot;</span>: <span class="number">4</span>,</span><br><span class="line">            <span class="attr">&quot;title&quot;</span>: <span class="string">&quot;Candy Shop&quot;</span>,</span><br><span class="line">            <span class="attr">&quot;author&quot;</span>: <span class="string">&quot;Mohamed&quot;</span>,</span><br><span class="line">            <span class="attr">&quot;imageUrl&quot;</span>: <span class="string">&quot;http://chaoyxy.cn/data/User/admin/home/desktop/images/background1.jpg&quot;</span></span><br><span class="line">        &#125;</span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>往数据库中插入数据</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 插入数据</span></span><br><span class="line">router.post(<span class="string">&#x27;/insertdata&#x27;</span>,<span class="function">(<span class="params">req,res</span>)=&gt;</span>&#123;</span><br><span class="line">    <span class="keyword">const</span> sqlStr = <span class="string">&#x27;INSERT INTO flutter_list SET ? &#x27;</span></span><br><span class="line">    <span class="keyword">const</span> value = req.body;</span><br><span class="line">    db.query(sqlStr,value,<span class="function">(<span class="params">err,result</span>)=&gt;</span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (err) &#123;</span><br><span class="line">            <span class="built_in">console</span>.log(err.message)</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            <span class="built_in">console</span>.log(<span class="string">&#x27;success&#x27;</span>)</span><br><span class="line">            res.send(&#123;</span><br><span class="line">                <span class="attr">status</span>:<span class="number">200</span>,</span><br><span class="line">                <span class="attr">mag</span>:<span class="string">&quot;插入成功&quot;</span></span><br><span class="line">            &#125;)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<img src="/blogs/2022/04/28/Express%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81/pic4.png" class title="往数据库中插入数据">

<p>**这里，我们的需要插入的目标值我们用 ‘ ? ‘ 代替了，在下面用value接收，到时候 value 可以直接替换了 ‘ ? ‘，这种写法可以防止SQL注入，也可以简化写法，SQL语句没必要写成 INSERT INTO flutter（id,title,author,imageUrl）VALUES (5,张三,李四,<a target="_blank" rel="noopener" href="http://baidu.com/">http://baidu.com</a>)  **</p>
<p>如果有多个参数需要传递，依然是可以的比如</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 插入数据 写法1</span></span><br><span class="line">router.post(<span class="string">&#x27;/insertdata1&#x27;</span>,<span class="function">(<span class="params">req,res</span>)=&gt;</span>&#123;</span><br><span class="line">    <span class="keyword">const</span> user = &#123;<span class="attr">username</span>:<span class="string">&quot;zhangsan&quot;</span>,<span class="attr">password</span>:<span class="string">&quot;lisi3210.&quot;</span>&#125;;</span><br><span class="line">    <span class="keyword">const</span> sqlStr = <span class="string">`INSERT INTO flutter_list (username,password) VALUES (&#x27;zhangsan&#x27;,&#x27;lisi3210.&#x27; )`</span>;</span><br><span class="line">    db.query(sqlStr,<span class="function">(<span class="params">err,result</span>)=&gt;</span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (err) &#123;</span><br><span class="line">            <span class="built_in">console</span>.log(err.message)</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            <span class="built_in">console</span>.log(<span class="string">&#x27;success&#x27;</span>)</span><br><span class="line">            res.send(&#123;</span><br><span class="line">                <span class="attr">status</span>:<span class="number">200</span>,</span><br><span class="line">                <span class="attr">mag</span>:<span class="string">&quot;插入成功&quot;</span></span><br><span class="line">            &#125;)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="comment">// 插入数据 写法2</span></span><br><span class="line">router.post(<span class="string">&#x27;/insertdata2&#x27;</span>,<span class="function">(<span class="params">req,res</span>)=&gt;</span>&#123;</span><br><span class="line">    <span class="keyword">const</span> user = &#123;<span class="attr">username</span>:<span class="string">&quot;zhangsan&quot;</span>,<span class="attr">password</span>:<span class="string">&quot;lisi3210.&quot;</span>&#125;;</span><br><span class="line">    <span class="keyword">const</span> sqlStr = <span class="string">&#x27;INSERT INTO flutter_list (username,password) VALUES (?,?) &#x27;</span>;</span><br><span class="line">    db.query(sqlStr,[user.username,user.password],<span class="function">(<span class="params">err,result</span>)=&gt;</span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (err) &#123;</span><br><span class="line">            <span class="built_in">console</span>.log(err.message)</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            <span class="built_in">console</span>.log(<span class="string">&#x27;success&#x27;</span>)</span><br><span class="line">            res.send(&#123;</span><br><span class="line">                <span class="attr">status</span>:<span class="number">200</span>,</span><br><span class="line">                <span class="attr">mag</span>:<span class="string">&quot;插入成功&quot;</span></span><br><span class="line">            &#125;)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="comment">// 插入数据 写法3</span></span><br><span class="line">router.post(<span class="string">&#x27;/insertdata3&#x27;</span>,<span class="function">(<span class="params">req,res</span>)=&gt;</span>&#123;</span><br><span class="line">    <span class="keyword">const</span> user = &#123;<span class="attr">username</span>:<span class="string">&quot;zhangsan&quot;</span>,<span class="attr">password</span>:<span class="string">&quot;lisi3210.&quot;</span>&#125;;</span><br><span class="line">    <span class="keyword">const</span> sqlStr = <span class="string">&#x27;INSERT INTO flutter_list SET ? &#x27;</span>;</span><br><span class="line">    db.query(sqlStr,user,<span class="function">(<span class="params">err,result</span>)=&gt;</span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (err) &#123;</span><br><span class="line">            <span class="built_in">console</span>.log(err.message)</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            <span class="built_in">console</span>.log(<span class="string">&#x27;success&#x27;</span>)</span><br><span class="line">            res.send(&#123;</span><br><span class="line">                <span class="attr">status</span>:<span class="number">200</span>,</span><br><span class="line">                <span class="attr">mag</span>:<span class="string">&quot;插入成功&quot;</span></span><br><span class="line">            &#125;)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>可以看出来，明显<strong>写法3</strong>要简洁许多</p>
<h2 id="2-跨域中间件"><a href="#2-跨域中间件" class="headerlink" title="2.跨域中间件"></a>2.跨域中间件</h2><p>因为浏览器有一个安全机制叫同源策略。同源就是指<strong>协议、域名、端口</strong>都一样，如果任意一项不一致就是不同源。简单点说就是，你的网页URL和你调用的接口URL不是一个地方的，浏览器觉得有安全风险，不想让你使用这个接口的数据。</p>
<p>举例：</p>
<p>如果你的页面URL是 <a target="_blank" rel="noopener" href="http://www.aaa.com/zzz.htm">http://www.aaa.com/zzz.htm</a> ，那么接口地址如下几种情况</p>
<ol>
<li><p><a target="_blank" rel="noopener" href="https://www.aaa.com/xxx">https://www.aaa.com/xxx</a> （不同源，因为协议不同）</p>
</li>
<li><p><a target="_blank" rel="noopener" href="http://www.aaa.com:8080/xxx">http://www.aaa.com:8080/xxx</a> （不同源，因为端口不同）</p>
</li>
<li><p><a target="_blank" rel="noopener" href="http://www.bbb.com/xxx">http://www.bbb.com/xxx</a> （不同源，因为域名不同）</p>
</li>
<li><p><a target="_blank" rel="noopener" href="http://abc.aaa.com/xxx">http://abc.aaa.com/xxx</a> （不同源，因为域名不同）</p>
</li>
<li><p><a target="_blank" rel="noopener" href="http://www.aaa.com/xxx">http://www.aaa.com/xxx</a> （同源，协议、域名、端口均相同）</p>
</li>
</ol>
<p>解决跨域的两种方法：</p>
<ol>
<li><p><strong>JSONP</strong>：首先我们先弄明白jsonp的原理，通俗的讲就是动态生成一个script，由于script不受同源策略的限制，就可以去请求不同域的接口了。相当于你自己买一碗兰州拉面，放到肯德基的袋子里，偷偷带到肯德基去吃。（不能解决POST等跨域问题）</p>
</li>
<li><p><strong>CORS</strong>：跨域资源共享。就是在后台服务器端允许某个域名下的请求。相当于兰州拉面馆和肯德基签一个供货协议，拉面馆把肯德基放到他们的供货清单里。<strong>（推荐这个）</strong></p>
</li>
</ol>
<p>express第三方提供了一个cors中间件，怎么使用呢？我们先来看看</p>
<p>首先安装中间件</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">npm install cors --save</span><br><span class="line"><span class="comment">// 导入中间件</span></span><br><span class="line"><span class="keyword">const</span> cors = <span class="built_in">require</span>(<span class="string">&#x27;cors&#x27;</span>);</span><br><span class="line"><span class="comment">// 注册中间件</span></span><br><span class="line">app.use(cors());</span><br></pre></td></tr></table></figure>

<p>推荐在全局开头注册跨域的中间件</p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="http://chaoyxy.cn/data/User/admin/home/desktop/images/alipay.jpg" alt=" 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="http://chaoyxy.cn/data/User/admin/home/desktop/images/wechatpay.jpg" alt=" 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blogs/tags/Node-js/" rel="tag"># Node.js</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blogs/2022/04/25/express%E4%B9%8B%E4%B8%AD%E9%97%B4%E4%BB%B6/" rel="next" title="express之中间件">
                <i class="fa fa-chevron-left"></i> express之中间件
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blogs/2022/04/28/Express%E4%B8%AD%E7%9A%84JWT%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81/" rel="prev" title="Express中的JWT身份认证">
                Express中的JWT身份认证 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a target="_blank" rel="noopener" href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/blogs/images/cat.jpg"
                alt="" />
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blogs/archives">
              
                  <span class="site-state-item-count">43</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/blogs/tags/index.html">
                  <span class="site-state-item-count">10</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://gitee.com/louchaoyy" target="_blank" title="Gitee">
                      
                        <i class="fa fa-fw fa-gitee"></i>Gitee</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="louchao@louchaoyy.cn" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Express%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81"><span class="nav-number">1.</span> <span class="nav-text">Express身份认证</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81"><span class="nav-number">1.1.</span> <span class="nav-text">1.身份认证</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-Session%E8%AE%A4%E8%AF%81%E6%9C%BA%E5%88%B6"><span class="nav-number">1.2.</span> <span class="nav-text">2.Session认证机制</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-Express%E4%B8%AD%E7%9A%84session%E8%AE%A4%E8%AF%81"><span class="nav-number">1.3.</span> <span class="nav-text">3.Express中的session认证</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E9%99%84%E5%BD%95%EF%BC%9A"><span class="nav-number">2.</span> <span class="nav-text">附录：</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-express-mysql"><span class="nav-number">2.1.</span> <span class="nav-text">1.express-mysql</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E8%B7%A8%E5%9F%9F%E4%B8%AD%E9%97%B4%E4%BB%B6"><span class="nav-number">2.2.</span> <span class="nav-text">2.跨域中间件</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<div class="copyright">&copy; <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Chaoyxy</span>

  
</div>

<span id="busuanzi_container_site_pv">
    本站总访问量<span id="busuanzi_value_site_pv"></span>次
</span>
<!--

  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.3</div>
-->




        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/blogs/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/blogs/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/blogs/js/src/motion.js?v=5.1.3"></script>



  
  


  <script type="text/javascript" src="/blogs/js/src/affix.js?v=5.1.3"></script>

  <script type="text/javascript" src="/blogs/js/src/schemes/pisces.js?v=5.1.3"></script>



  
  <script type="text/javascript" src="/blogs/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/blogs/js/src/post-details.js?v=5.1.3"></script>



  


  <script type="text/javascript" src="/blogs/js/src/bootstrap.js?v=5.1.3"></script>



  


  

    
      <script id="dsq-count-scr" src="https://Chaoyxy.disqus.com/count.js" async></script>
    

    
      <script type="text/javascript">
        var disqus_config = function () {
          this.page.url = 'https://louchaoyy.gitee.io/blogs/2022/04/28/Express%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81/';
          this.page.identifier = '2022/04/28/Express身份认证/';
          this.page.title = 'Express身份认证';
        };
        var d = document, s = d.createElement('script');
        s.src = 'https://Chaoyxy.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      </script>
    

  




	





  














  





  

  

  

  
  

  

  

  

</body>
</html>
